package icu.lookyousmileface.deadlock;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author starrysky
 * @title: DeadLockTest
 * @projectName Juc_Pro
 * @description: 死锁测试
 * @date 2021/1/309:46 下午
 */
public class DeadLockTest {
    public static void main(String[] args) {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                5,
                Runtime.getRuntime().availableProcessors(),
                5, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(3),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy()
        );

        try {
            threadPoolExecutor.execute(new MyDeadThread("lockA","lockB"));

            threadPoolExecutor.execute(new MyDeadThread("lockB","lockA"));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        threadPoolExecutor.shutdown();
        }
    }
}
